package com.woniuxy.project.campus.canteen.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.project.campus.canteen.dto.ShopInfoDto;
import com.woniuxy.project.campus.canteen.model.Shops;
import com.woniuxy.project.campus.canteen.param.UpdateShopInfoParam;
import com.woniuxy.project.campus.canteen.service.ShopsService;
import com.woniuxy.project.campus.canteenModelform.*;
import com.woniuxy.project.campus.util.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 猫将军
 * @since 2025年02月17日
 */
@RestController
@RequestMapping("/shops")
public class ShopsController {

    @Resource
    private ShopsService shopsService;

    //商户添加店铺详情接口

    @RequestMapping("/addShopInfo")
    public Result addShopInfo(@RequestHeader("token") String token, UpdateShopInfoForm shopinfo) throws Exception{
        UpdateShopInfoParam bean = BeanUtil.toBean(shopinfo, UpdateShopInfoParam.class);
        bean.setToken(token);
        shopsService.addShopInfo(bean);
        return Result.success(null);
    }

    //通过商铺id查询商铺名
    @GetMapping("/getShopInfo")
    public Result getShopInfo( @RequestParam("shopId") Integer shopId) throws Exception{
        String shopName = shopsService.getShopName(shopId);
        return Result.success(shopName);
    }

    //商家查询店铺详情接口
    @GetMapping("/getShopDetail")
    public Result getShopDetail(@RequestHeader("token") String token) throws Exception{
        Shops shopInfo = shopsService.getShopDetail(token);
        return Result.success(shopInfo);
    }

    //商家查询店铺详情接口
    @ApiOperation(value = "查询店铺详情")
    @GetMapping("/ShopInfoDto")
    public Result ShopInfoDto(@RequestHeader("token") String token) throws Exception{
        ShopInfoDto shopInfo = shopsService.ShopInfoDto(token);
        return Result.success(shopInfo);
    }

    //修改店铺信息接口
    @ApiOperation(value = "修改店铺信息")
    @RequestMapping("/editYourStoreDetails")
    public Result editYourStoreDetails(@RequestHeader("token") String token, XiuShopInfoForm xiuShopInfoForm) throws IOException {
        shopsService.editYourStoreDetails(token,xiuShopInfoForm);
        return Result.success("修改成功");
    }


    //商家修改配送费和起送金额接口
    @ApiOperation(value = "修改配送费和起送金额")
    @PostMapping("/editShopTime")
    public Result editShopTime(@RequestHeader("token") String token, @RequestBody EditShopTimeForm editShopTime) throws Exception{
        shopsService.editShopTime(token,editShopTime);
        return Result.success("修改成功");
    }
    //获取商家配送费和起送金额接口
    @ApiOperation(value = "获取商家配送费和起送金额")
    @GetMapping("/getShopMessage")
    public Result getShopMessage(@RequestHeader("token") String token) throws Exception{
        EditShopTimeForm editShopTime = shopsService.getShopMessage(token);
        return Result.success(editShopTime);
    }
    //是否营业接口
    @ApiOperation(value = "修改是否营业")
    @PostMapping("/isOperating")
    public Result isOperating(@RequestHeader("token") String token,@RequestBody IsOperatingForm isOpen) throws Exception{
        shopsService.isOperating(token,isOpen);
        return Result.success(isOpen);
    }

    //查询是否营业接口

    @ApiOperation(value = "查询是否营业")
    @GetMapping("/getOperating")
    public Result getOperating(@RequestHeader("token") String token) throws Exception{
        Boolean isOpen = shopsService.getOperating(token);
        return Result.success(isOpen);
    }

    //通过accessId 查询商铺id
    @ApiOperation(value = "通过accessId 查询商铺id")
    @GetMapping("/getShopIdByAccessId")
    public Result getShopIdByAccessId(@RequestParam("accessId") Integer accessId) throws Exception{
        Integer shopId = shopsService.getShopIdByAccessId(accessId);
        return Result.success(shopId);
    }


}

